import Request from '../utils/request.js';

/**
 * 微信登录相关API
 */
class AuthApi {
  /**
   * 微信静默登录 - 通过code获取openId
   * @param {string} code 微信授权码
   * @returns {Promise} 返回包含openId的Promise
   */
  static async otherQuiesceLogin(code,inviterId,channel) {
    return Request.post('/api/member/auth/other/login/quiesce', {
      loginCode: code,
      inviterId: inviterId,
      channel: channel
    });
  }


  /**
   * 微信OpenId登录 - 刷新用户登录信息
   * @param {string} openId 微信OpenId
   * @returns {Promise} 返回登录信息
   */
  static async otherOpenIdLogin (openId,channel) {
    return Request.post('/api/member/auth/other/login/openId', {
      openId: openId,
      channel: channel
    });
  }
  /**
   * 微信手机号登录
   * @param {string} code 微信授权码
   * @param {string} encryptedData 加密数据
   * @param {string} iv 初始向量
   * @returns {Promise}
   */
  static async otherPhoneLogin(code, encryptedData, iv) {
    return Request.post('/api/member/auth/other/login/phone', {
      code,
      encryptedData,
      iv
    });
  }

  /**
   * 微信手机号注册
   * @param {string} phoneCode 手机号授权码
   * @returns {Promise}
   */
  static async otherRegisterPhone(phoneCode, sign, channel) {
    return Request.post('/api/member/auth/other/register/phone', {
      phoneCode: phoneCode,
      sign: sign,
      channel: channel
    });
  }

  /**
   * 刷新访问令牌
   * @param {string} refreshToken 刷新令牌
   * @returns {Promise}
   */
  static async refreshToken(refreshToken) {
    return Request.post('/api/member/auth/refresh-token', {
      refreshToken
    });
  }

  /**
   * 退出登录
   * @returns {Promise}
   */
  static async logout() {
    return Request.post('/api/member/auth/logout');
  }


}

export default AuthApi;